# Copyright 2012 Brett Ponsler
# This file is part of siriviewer.
#
# siriviewer is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# siriviewer is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with siriviewer.  If not, see <http://www.gnu.org/licenses/>.
''' '''
from siriviewer.objects.button import Button
from siriviewer.objects.addViews import AddViews
from siriviewer.objects.speechRequest import SpeechRequest
from siriviewer.objects.assistantUtteranceView import AssistantUtteranceView


class Factory:
    ''' '''
    __Objects = [AddViews, AssistantUtteranceView, Button, SpeechRequest]

    # Create the list of object names from the list of objects
    __ObjectNames = map(lambda cls: cls.__name__, __Objects)

    # Create the map of object names to actual objects
    __ObjectMap = dict(zip(__ObjectNames, __Objects))

    @classmethod
    def create(cls, controller, obj, width, height, *args, **kwargs):
        ''' '''
        returnObject = None
        className = obj.get('class')

        if className is not None and className in cls.__ObjectMap:
            returnObject = cls.__ObjectMap[className](controller, obj, width,
                                                      height, *args, **kwargs)

        return returnObject


if __name__ == '__main__':
    print Factory.create(None, {"class": "AddViews"})
